'''
Author: mypx
Date: 2025-10-21 15:28:42
LastEditTime: 2025-10-21 15:30:19
LastEditors: mypx mypx_coder@163.com
Description: 
'''
# 数据模型定义
from dataclasses import dataclass, field
from typing import List, Dict, Any, Optional, Union

@dataclass
class Condition:
    """条件表达式类"""
    expression: str
    evaluated: bool = False  # 经过表达式解析器计算后的结果

@dataclass
class DefaultValue:
    """默认值类"""
    value: Any
    condition: Optional[Condition] = None

@dataclass
class Selection:
    """选择关系类"""
    target: str
    condition: Optional[Condition] = None

@dataclass
class RangeRestriction:
    """范围限制类"""
    min: int
    max: int
    condition: Optional[Condition] = None

@dataclass
class ConfigProperty:
    """配置项属性类"""
    type: Optional[str] = None  # 'bool', 'tristate', 'string', 'int', 'hex'
    prompt: Optional[str] = None
    depends_on: Optional[Condition] = None
    visible_if: Optional[Condition] = None
    default: Optional[DefaultValue] = None
    help: Optional[str] = None
    select: List[Selection] = field(default_factory=list)
    imply: List[Selection] = field(default_factory=list)
    range: Optional[RangeRestriction] = None

@dataclass
class ConfigItem:
    """配置项类"""
    id: str
    name: str
    properties: ConfigProperty
    parent: Optional['ConfigItem'] = None
    children: List[Union['ConfigItem', 'MenuItem', 'CommentItem', 'ChoiceItem']] = field(default_factory=list)
    is_selected: bool = False
    is_enabled: bool = True
    is_visible: bool = True
    current_value: Any = None

@dataclass
class MenuItem:
    """菜单项类"""
    id: str
    name: str
    prompt: str
    parent: Optional['MenuItem'] = None
    children: List[Union[ConfigItem, 'MenuItem', 'CommentItem', 'ChoiceItem']] = field(default_factory=list)
    is_expanded: bool = False

@dataclass
class CommentItem:
    """注释项类"""
    id: str
    text: str
    condition: Optional[Condition] = None

@dataclass
class ChoiceItem:
    """选择组类"""
    id: str
    prompt: Optional[str] = None
    optional: bool = False  # 是否允许不选
    children: List[ConfigItem] = field(default_factory=list)
    selected_item: Optional[str] = None  # 当前选中的配置项ID
